package cn.edu.xmu.oomall.wechatpay.mq;

import cn.edu.xmu.oomall.wechatpay.microservice.WeChatPayNotifyService;
import cn.edu.xmu.oomall.wechatpay.model.vo.WeChatPayPaymentNotifyRetVo;
import cn.edu.xmu.oomall.wechatpay.util.Constant;
import cn.edu.xmu.privilegegateway.annotation.util.JacksonUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.web.context.request.RequestContextHolder;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Map;


@Service
@RocketMQMessageListener(topic = "wechatpaypayment-topic1", consumeMode = ConsumeMode.CONCURRENTLY, consumerGroup = "wechatpaypayment-group1")
public class PaymentNotifyService implements RocketMQListener<String> {
    @Resource
    WeChatPayNotifyService weChatPayNotifyService;

    @Override
    public void onMessage(String json) {

        //System.out.println(LocalDateTime.now()+":微信发送支付结果通过回调给支付系统");
        RequestContextHolder.setRequestAttributes(Constant.servletRequestAttributes);

        WeChatPayPaymentNotifyRetVo weChatPayPaymentNotifyRetVo= JSONObject.parseObject(json,WeChatPayPaymentNotifyRetVo.class);
        weChatPayNotifyService.paymentNotify(weChatPayPaymentNotifyRetVo);
        //System.out.println(LocalDateTime.now()+"微信发送支付结果回调给支付系统成功");
    }
}